package com.jwgf.common;

import android.util.SparseArray;
import android.util.SparseIntArray;

import com.jwgf.smarowindingmachine_unity.R;
import com.jwgf.smarowindingmachine_unity.ui.EquipmentMaintenanceAuthoritySettingFragment;
import com.jwgf.smarowindingmachine_unity.ui.EquipmentMaintenanceDeviceSettingFragment;
import com.jwgf.smarowindingmachine_unity.ui.EquipmentMaintenanceFunctionFragment;
import com.jwgf.smarowindingmachine_unity.ui.EquipmentMaintenanceMenuFragment;
import com.jwgf.smarowindingmachine_unity.ui.EquipmentMaintenanceNetworkSettingFragment;
import com.jwgf.smarowindingmachine_unity.ui.EquipmentMaintenanceSoftwareUpgradeFragment;
import com.jwgf.smarowindingmachine_unity.ui.EquipmentMaintenanceSpindleUpgradeFragment;
import com.jwgf.smarowindingmachine_unity.ui.LoginFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateCbfLogFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateCbfStateFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateDirectCurrentFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateDofferLogFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateDofferStateFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateFaultNavigationFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateMachineLogFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateMachineStatisticFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateMenuFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateRunningStateFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateSpindleLogFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateSpindleStateFragment;
import com.jwgf.smarowindingmachine_unity.ui.MachineStateSpindleStatisticFragment;
import com.jwgf.smarowindingmachine_unity.ui.MainMenuFragment;
import com.jwgf.smarowindingmachine_unity.ui.ParameterSettingCbfParameterFragment;
import com.jwgf.smarowindingmachine_unity.ui.ParameterSettingDofferParameterFragment;
import com.jwgf.smarowindingmachine_unity.ui.ParameterSettingGroupFragment;
import com.jwgf.smarowindingmachine_unity.ui.ParameterSettingInSegmentParameterFragment;
import com.jwgf.smarowindingmachine_unity.ui.ParameterSettingMachineParameterFragment;
import com.jwgf.smarowindingmachine_unity.ui.ParameterSettingMenuFragment;
import com.jwgf.smarowindingmachine_unity.ui.ParameterSettingSpindleParameterFragment_craft;
import com.jwgf.smarowindingmachine_unity.ui.ParameterSettingSystemParameterFragment;
import com.jwgf.smarowindingmachine_unity.ui.ProductionManagementChangeClassSettingFragment;
import com.jwgf.smarowindingmachine_unity.ui.ProductionManagementMenuFragment;
import com.jwgf.smarowindingmachine_unity.ui.ProductionManagementShiftReportFragmentRx;
import com.jwgf.smarowindingmachine_unity.ui.ProductionManagementStatisticsReportFragment;
import com.jwgf.smarowindingmachine_unity.ui.ProductionManagementVarietyManagementFragment;
import com.jwgf.smarowindingmachine_unity.ui.TitleFragment;

import java.util.HashMap;


public class FragmentRelationShip {
    private SparseArray<Class> map = new SparseArray<Class>();
    // private SparseIntArray right = new SparseIntArray();
    //private HashMap<Integer, Boolean> right = new HashMap<Integer, Boolean>();
    private HashMap<Integer, Integer> right = new HashMap<Integer, Integer>();
    private static FragmentRelationShip instance = new FragmentRelationShip();

    private SparseIntArray writeLevel = new SparseIntArray();
    private SparseIntArray readLevel = new SparseIntArray();

    public static FragmentRelationShip getInstance() {
        return instance;
    }

    private FragmentRelationShip() {
        // first menu button and tag map
        map.put(R.id.machine_state_button, MachineStateMenuFragment.class);
        map.put(R.id.parameter_setting_button, ParameterSettingMenuFragment.class);
        map.put(R.id.product_manage_button, ProductionManagementMenuFragment.class);
        map.put(R.id.equipment_maintenance_button, EquipmentMaintenanceMenuFragment.class);

        // second menu button and tag map
        map.put(R.id.running_state_button, MachineStateRunningStateFragment.class);
        map.put(R.id.machine_log_button, MachineStateMachineLogFragment.class);
        map.put(R.id.machine_statistic_button, MachineStateMachineStatisticFragment.class);
        map.put(R.id.spindle_status_button, MachineStateSpindleStateFragment.class);
        map.put(R.id.spindle_log_button, MachineStateSpindleLogFragment.class);
        map.put(R.id.spindle_statistic_button, MachineStateSpindleStatisticFragment.class);
        map.put(R.id.cbf_status_button, MachineStateCbfStateFragment.class);
        map.put(R.id.cbf_log_button, MachineStateCbfLogFragment.class);
        map.put(R.id.doffer_status_button, MachineStateDofferStateFragment.class);
        map.put(R.id.doffer_log_button, MachineStateDofferLogFragment.class);
        map.put(R.id.direct_current_button, MachineStateDirectCurrentFragment.class);
        map.put(R.id.fault_navigation_button, MachineStateFaultNavigationFragment.class);

        map.put(R.id.btn_system,
                ParameterSettingSystemParameterFragment.class);
        map.put(R.id.btn_machine,
                ParameterSettingMachineParameterFragment.class);
        map.put(R.id.btn_in_segment,
                ParameterSettingInSegmentParameterFragment.class);
        map.put(R.id.btn_group,
                ParameterSettingGroupFragment.class);
        map.put(R.id.btn_spindle,
                ParameterSettingSpindleParameterFragment_craft.class);
        map.put(R.id.btn_tube_process,
                ParameterSettingCbfParameterFragment.class);
        map.put(R.id.btn_spooling_device,
                ParameterSettingDofferParameterFragment.class);


        map.put(R.id.pm_productionset,
                ProductionManagementChangeClassSettingFragment.class);
        map.put(R.id.variety_management_button,
                ProductionManagementVarietyManagementFragment.class);
        map.put(R.id.pm_duty_reported,
                ProductionManagementShiftReportFragmentRx.class);
        map.put(R.id.pm_statisticreport, ProductionManagementStatisticsReportFragment.class);

//		//
        map.put(R.id.btn_function,
                EquipmentMaintenanceFunctionFragment.class);
        map.put(R.id.btn_spindle_upgrade, EquipmentMaintenanceSpindleUpgradeFragment.class);
        map.put(R.id.btn_password,
                EquipmentMaintenanceAuthoritySettingFragment.class);
        map.put(R.id.btn_upgrade,
                EquipmentMaintenanceSoftwareUpgradeFragment.class);
        map.put(R.id.btn_network,
                EquipmentMaintenanceNetworkSettingFragment.class);
        map.put(R.id.btn_device,
                EquipmentMaintenanceDeviceSettingFragment.class);

        if (!AppContext.isDebug) {
            // second menu button and right map
            // 设置进入该页面是否需要密码
            writeLevel.put(R.id.btn_system, 2);
            readLevel.put(R.id.btn_system, 1);

            writeLevel.put(R.id.btn_machine, 2);
            readLevel.put(R.id.btn_machine, 1);


            writeLevel.put(R.id.btn_in_segment, 2);
            readLevel.put(R.id.btn_in_segment, 1);

            writeLevel.put(R.id.btn_group, 2);
            readLevel.put(R.id.btn_group, 1);

            writeLevel.put(R.id.btn_spindle, 2);
            readLevel.put(R.id.btn_spindle, 1);


            writeLevel.put(R.id.btn_tube_process, 2);
            readLevel.put(R.id.btn_tube_process, 1);

            writeLevel.put(R.id.btn_spooling_device, 2);
            readLevel.put(R.id.btn_spooling_device, 1);

            // 1:low   2:middle  3:high
            writeLevel.put(R.id.pm_productionset, 1);
            readLevel.put(R.id.pm_productionset, 1);

            writeLevel.put(R.id.variety_management_button, 1);
            readLevel.put(R.id.variety_management_button, 1);

            writeLevel.put(R.id.btn_function, 3);
            readLevel.put(R.id.btn_function, 3);

//		writeLevel.put(R.id.btn_print, 3);
//		readLevel.put(R.id.btn_print, 3);

            writeLevel.put(R.id.btn_password, 3);
            readLevel.put(R.id.btn_password, 3);

            writeLevel.put(R.id.btn_upgrade, 3);
            readLevel.put(R.id.btn_upgrade, 3);

            writeLevel.put(R.id.btn_network, 3);
            readLevel.put(R.id.btn_network, 3);

            writeLevel.put(R.id.btn_device, 3);
            readLevel.put(R.id.btn_device, 3);
        }

    }

    public String getLoginTag() {
        return LoginFragment.class.getName();
    }

    public Integer getWriteLevel(int id) {
        return writeLevel.get(id);
    }

    public Integer getReadLevel(int id) {
        return readLevel.get(id);
    }

    public String getTag(int id) {
        if (map.get(id) != null) {
            return map.get(id).getName();
        } else {
            return null;
        }
    }

    public String getMainTag() {
        return MainMenuFragment.class.getName();
    }

    public String getTitleTag() {
        return TitleFragment.class.getName();
    }


    public Integer getRight(int id) {
        return right.get(id);
    }

    public int getId(String tag) {
        for (int i = 0; i < map.size(); ++i) {
            String value = map.valueAt(i).getName();
            if (value.equals(tag)) {
                return map.keyAt(i);
            }
        }
        return -1;
    }

    public boolean isContentContainer(int container) {
        if (container == R.id.content_layout) {
            return true;
        } else {
            return false;
        }
    }
}
